package com.eric.controller;
import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.dev33.satoken.annotation.SaCheckRole;
import cn.dev33.satoken.annotation.SaMode;
import cn.dev33.satoken.util.SaResult;
import com.eric.domain.dto.LocationDto;
import com.eric.service.ILocationService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;


/**
 * <p>
 * 所在地，用于存储仓库、项目所在地 前端控制器
 * </p>
 *
 * @author 新哥
 * @since 2024-03-23
 */
@RestController
@RequestMapping("/location")
@RequiredArgsConstructor
public class LocationController {

    private final ILocationService locationService;

    /*
     * 新增一条所在地数据
     * */
    @PostMapping("/saveOne")
    @SaCheckRole(value = {"sys:coder","sys:superAdmin","sys:admin"},mode = SaMode.OR)
    public SaResult addOneLocation(@RequestBody LocationDto locationDto){
        return locationService.saveOneService(locationDto);
    }

    /*
     * 修改一条数据
     * */
    @PutMapping("/modifyOne")
    @SaCheckPermission("sys:modify")
    @SaCheckRole(value = {"sys:coder","sys:superAdmin","sys:admin"},mode = SaMode.OR)
    public SaResult modifyOneLocation(@RequestBody LocationDto locationDto){
        return locationService.modifyOneService(locationDto);
    }

    //    根据id删除一条数据
    @DeleteMapping("/{id}")
    @SaCheckRole(value = {"sys:coder","sys:superAdmin","sys:admin"},mode = SaMode.OR)
    @SaCheckPermission("sys:delete")
    public SaResult deleteOneLocationById(@PathVariable("id") Integer id){
        return locationService.deleteOneLocationByIdService(id);
    }

    //    分页查询所有数据
    @GetMapping("/all")
    public SaResult getAllLocationList(Integer pageCount,Integer pageSize){
        return locationService.getAllLocationListService(pageCount,pageSize);
    }

    //    根据id查询一条数据
    @GetMapping("/{id}")
    public SaResult getOneById(@PathVariable("id") Integer id ){
        return locationService.getOneByIdService(id);
    }

    //    根据地址模糊查询数据
    @GetMapping("/getByAddress")
    public SaResult getAllByAddress(String address,Integer pageCount,Integer pageSize ){
        return locationService.getByAddressService(address,pageCount,pageSize);
    }

    //    根据userId查询数据
    @GetMapping("/getByUserId")
    public SaResult getAllByUserId(Integer userId,Integer pageCount,Integer pageSize){
        return locationService.getAllByUserIdService(userId,pageCount,pageSize);
    }
    //    根据projectId查询数据
    @GetMapping("/getByProjectId")
    public SaResult getAllByProjectId(Integer projectId,Integer pageCount,Integer pageSize){
        return locationService.getAllByProjectIdServie(projectId,pageCount,pageSize);
    }

    //    根据warehouseId参训数据
    @GetMapping("/getByWarehouseId")
    public SaResult getAllByWarehouseId(Integer warehouseId,Integer pageCount,Integer pageSize){
        return locationService.getAllByWarehouseIdServie(warehouseId,pageCount,pageSize);
    }

    //    获取当前登录用户所在地
    @GetMapping("/getByLoginId")
    public String getAllByLoginId(){
        return locationService.getAllByLoginId();
    }
}
